package com.iamsleeping;

import android.app.Activity;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.telephony.PhoneStateListener;
import android.telephony.SmsManager;
import android.telephony.TelephonyManager;
import android.text.format.DateFormat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TimePicker;
import android.widget.Toast;
import android.widget.ToggleButton;

import java.util.Calendar;

public class SettingsActivity extends FragmentActivity {
    EditText messageText;
    ToggleButton appStatus;
    ToggleButton doNotDisturb;
    ToggleButton autoCutCalls;
    Settings settings;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
        settings = Settings.getInstance(getApplicationContext());
        appStatus = (ToggleButton) findViewById(R.id.appToggleButton);
        doNotDisturb = (ToggleButton) findViewById(R.id.doNotDisturbButton);
        autoCutCalls = (ToggleButton) findViewById(R.id.autoCutButton);
        messageText = (EditText) findViewById(R.id.messageText);
        paintUI();
    }

    public void paintUI() {
        appStatus.setChecked(settings.getAppStatus());
        doNotDisturb.setChecked(settings.getDoNotDisturb());
        autoCutCalls.setChecked(settings.getAutoCutCalls());
        messageText.setText(settings.getMsgText());
    }

    public void onAppStatusToggled(View view) {
        settings.toggleAppStatus();
    }

    public void onDoNotDisturbToggled(View view) {
        settings.toggleDoNotDisturb();
    }

    public void onAutoCutToggled(View view) {
        settings.toggleAutoCutCalls();
    }

    public void onSetAlarmToggled(View view) {
        settings.toggleSetAlarm();
        if(settings.getSetAlarm()){
        	
            AlarmPickerFragment fragment = new AlarmPickerFragment();
            fragment.show(getSupportFragmentManager(), "timePicker");
            
        }
    }
}

